<template>
	<view>
		<u-navbar placeholder fixed autoBack title="人员搜索"></u-navbar>
		<view class="search u-border-bottom d-p-l-30 d-p-r-30 d-p-t-20 d-p-b-20 d-flex">
			<view class="input d-flex d-flex-1">
				<u-icon name="search" size="38rpx" color="#ADB4BD"></u-icon>
				<view class="d-flex-1"><u--input v-model="keyWord" border="none" style="padding: 0;height: 75rpx;" placeholder="请输入人员姓名/证件号码查询信息"></u--input></view>
			</view>
			<u-button text="搜索" @click="search" type="primary" :customStyle="{ width: '136rpx', height: '75rpx', marginLeft: '20rpx' }"></u-button>
		</view>
		<u-gap height="115rpx" bgColor="#ffffff"></u-gap>

		<view class="d-p-30">
			<template v-if="list && list.length > 0">
				<view class="d-m-b-30 card d-p-30" v-for="(item, index) in list" :key="index" @click="memberDetail(item)">
					<view class="d-flex">
						<view class="d-font-28" style="font-weight: bold;color: #151C24;">{{ item.xm }}</view>
						<view class="d-font-28 d-m-l-70" style="color: #5D6672;">{{ item.xb }}</view>
						<view class="d-m-l-20 d-m-r-20"><u-line direction="col" length="36rpx" color="#DFDFDF"></u-line></view>
						<view class="tag d-flex">{{ item.smrz }}</view>
						<view class="d-m-l-20 d-m-r-20"><u-line direction="col" length="36rpx" color="#DFDFDF"></u-line></view>
						<view class="d-font-28" style="color: #21A5F3;">{{ item.ryzt }}</view>
						<view class="d-flex-1"></view>
					</view>
					<view class="d-flex d-font-24 d-m-t-20">
						<view class="d-flex" style="flex: 3;">
							<view class="d-m-r-20" style="color: #5D6672;">证件号码</view>
							<view style="color: #162233;">{{ item.zjhm }}</view>
						</view>
						<view class="d-flex" style="flex: 2;">
							<view class="d-m-r-20" style="color: #5D6672;">所属区划</view>
							<view style="color: #162233;">{{ item.districtName }}</view>
						</view>
					</view>
					<view class="d-flex d-font-24 d-m-t-20">
						<view class="d-flex" style="flex: 3;">
							<view class="d-m-r-20" style="color: #5D6672;">项目名称</view>
							<view class="d-flex-1" style="color: #162233;">{{ item.gcmc }}</view>
						</view>
						<view class="d-flex" style="flex: 2;">
							<view class="d-m-r-20" style="color: #5D6672;">角色工种</view>
							<view style="color: #162233;">{{ item.zwzc }}</view>
						</view>
					</view>
					<view class="d-flex d-font-24 d-m-t-20">
						<view class="d-flex" style="flex: 3;">
							<view class="d-m-r-20" style="color: #5D6672;">班组名称</view>
							<view class="d-flex-1" style="color: #162233;">{{ item.bzmc }}</view>
						</view>
						<view class="d-flex" style="flex: 2;">
							<view class="d-m-r-20" style="color: #5D6672;">当天考勤</view>
							<view style="color: #ADB4BD;">{{ item.attendance }}</view>
						</view>
					</view>
					<view class="d-flex d-font-24 d-m-t-20">
						<view class="d-flex" style="flex: 3;">
							<view class="d-m-r-20" style="color: #5D6672;">本月工资</view>
							<view style="color: #ADB4BD;">{{ item.salary }}</view>
						</view>
					</view>
				</view>
			</template>
			<template v-else>
				<view style="padding-top: 14vh;"><u-empty icon="/static/image/none.png" :text="!show ? '请输入关键词进行查询' : '暂未搜索到相关数据'"></u-empty></view>
			</template>
		</view>
	</view>
</template>

<script>
import { staffs } from '../../../common/api.js';
export default {
	data() {
		return {
			list: [],
			pageNum: 1,
			pageSize: 20,
			pageLast: 1,
			show: false,
			keyWord: ''
		};
	},
	onReachBottom() {
		if (this.pageLast > this.pageNum) {
			uni.showLoading({
				title: '加载中...',
				mask: true
			});
			++this.pageNum;
			this.getList().then(e => {
				this.list = this.list.concat(e.data);
				uni.hideLoading();
			});
		}
	},
	methods: {
		init() {
			this.pageNum = 1;
			this.getList().then(e => {
				this.list = e.data;
				this.pageLast = Math.ceil(e.total / this.pageSize);
				this.show = true;
				uni.hideLoading();
			});
		},
		getList() {
			return staffs({
				params: {
					deptId: this.$user.deptId,
					pageSize: this.pageSize,
					pageNum: this.pageNum,
					keyWord: this.keyWord
				}
			});
		},
		search() {
			if (!this.keyWord) {
				return uni.$u.toast('请输入关键词进行查询');
			}
			uni.showLoading({
				title: '加载中...',
				mask: true
			});
			this.init();
		},
		memberDetail(item) {
			uni.$u.route({
				url: '/pages/index/member/memberDetail',
				params: {
					id: item.id
				}
			});
		}
	}
};
</script>

<style lang="scss">
.search {
	position: fixed;
	left: 0;
	right: 0;
	z-index: 999;
	background-color: #ffffff;
	.input {
		height: 75rpx;
		background: #f6f7f8;
		border-radius: 10rpx;
		padding: 0 20rpx;
	}
}
.card {
	box-shadow: 0rpx 5rpx 10rpx rgba(0, 0, 0, 0.05);
	border-radius: 10rpx;
	background-color: #ffffff;
	.tag {
		height: 32rpx;
		background: #ffb61d;
		border-radius: 4rpx;
		color: #ffffff;
		font-size: 20rpx;
		padding: 0 10rpx;
	}
}
page {
	background-color: #fbfcfc;
}
</style>
